<?php
session_start();
include("../include/util.inc.php");

function getperqst($category, $level, $question, $answer, $public)
{
    $pdo = getPDO();
    $category = $pdo->quote($category);
    $question = $pdo->quote($question);
    $answer = $pdo->quote($answer);
    $uid = $_SESSION['uid'];

    
    // add question
    if ($public != 'public') {
        $sql = "INSERT INTO question(`category`, `level`,`question`,`answer`,`property`) VALUES($category,$level,$question,$answer,$uid)";
        $pdo->query($sql);
        return "success";
    } else {
        $sql = "INSERT INTO question(`category`, `level`,`question`,`answer`,`property`) VALUES($category,$level,$question,$answer,0)";
        $pdo->query($sql);
        return "success";
    }
}


try {
    $category = $_POST['category'];
    $level = $_POST['level'];
    $question = $_POST['question'];
    $answer = $_POST['answer'];
    $public = $_POST['public'];
    echo getperqst($category, $level, $question, $answer, $public);
} catch (\PDOException $e) {
    echo $e->getMessage();
}


?>